﻿using System;

namespace _23_框架提供的委托类型有action和Func_委托与事件
{
    class Program
    {
        static void Main(string[] args)
        {
            Action<string, int> d1 = TestA;
            d1("Bob", 28);
            Action<string> d2 = TestB;
            d2("Jim");

            //使用Func委托绑定TestC和TestD方法
            Func<DateTime, int> d3 = TestC;
            Console.WriteLine("今年是{0}年。", d3(DateTime.Today));
            Func<int, int, long> d4 = TestD;
            long res = d4(2, 4);
            Console.WriteLine("计算结果:{0}", res);
        }

        static void TestA(string name,int age)
        {
            Console.WriteLine($"{name}今年{age}岁了");
        }

        static void TestB(string name)
        {
            Console.WriteLine("您好，{0}", name);
        }
        static int TestC(DateTime dt)
        {
            return dt.Year;
        }
        static long TestD(int start,int end)
        {
            long r = 1L;
            int cur = start;
            while (cur<=end)
            {
                r *= cur;
                cur++;
            }
            return r;
        }
    }
}
